home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15140 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  56 lines

  1. Path: news.cybercom.net!usenet
  2. From: nield@cybercom.net (John Nield)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: returning an array from function
  5. Date: Wed, 03 Apr 1996 21:33:01 GMT
  6. Organization: Cyber Access Internet Services (617) 396-0491
  7. Message-ID: <4juqrp$250@orion.cybercom.net>
  8. References: <4jstd8$kh0@news1.sunbelt.net>
  9. Reply-To: nield@cybercom.net
  10. NNTP-Posting-Host: dial2-9.cybercom.net
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. bourne@infoave.net (Rick Huebner) wrote:
  14.  
  15. >I have looked in several texts and looked through the faq for this question
  16. >and can't find a reference for my answer.  I am trying to return an array, or
  17. >a pointer to the array, from a function.  I have seen several examples of
  18. >returning a pointer, but it doesn't seem to work for me.  My function is going
  19. >to return an array of integers where 1-80 of them will be significant.  The
  20. >calling function will know how many integers are expected and will read them
  21. >off the array....If I can get the pointer back to the array.  A friend of mine
  22. >told me to just make the array a global, but I don't want to do that if I can
  23. >help it.  I would even resort to a recursive function that will pass the
  24. >integers back one at a time if that is possible.  Does anyone have any
  25. >suggestions?  I am open to anything and will go looking if you can tell me
  26. >where(hopefully online somewhere).
  27.  
  28. >Thanks...
  29.  
  30. #define ARRAY_SIZE 80
  31.  
  32. main()
  33. {
  34. int array[ARRAY_SIZE];
  35.         
  36.     fillarray(array);
  37. }
  38.  
  39. void fillarray(int *array_pntr)
  40. {
  41. int i;
  42.  
  43.     for (i=0; i < ARRAY_SIZE; i++)
  44.     {
  45.         printf("\nEnter an Integer:");
  46.         scanf("%d", &array_pntr[i]); /* write to memory address of element i
  47.                                         of the array */
  48.     }
  49. /* you dont need to return anything */
  50. }
  51.  
  52. I hope that's what you ment by your question.
  53.  
  54. ;jn
  55.  
  56.